/*********************************************************************************
 *      Copyright:  (C) 2020 Juan
 *                  All rights reserved.
 *
 *       Filename:  destroy.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(22/07/20)
 *         Author:  wangruijie <1046299465@qq.com>
 *      ChangeLog:  1, Release initial version on "22/07/20 03:47:59"
 *                 
 ********************************************************************************/
#include"G4module_server.h"

/* ************************************
 * 函数名：destroy_sock_ev_write()
 * 功能：销毁写事件完成后的结构体
 * 参数：定义后的结构体， sock_ev_write_struct
 * 返回值：
 *  ***********************************/
void destroy_sock_ev_write(struct sock_ev_write* sock_ev_write_struct)
{
    if(NULL != sock_ev_write_struct)
    {
        if(NULL != sock_ev_write_struct->write_ev)
        {
            free(sock_ev_write_struct->write_ev);   //释放write_ev
        }
        if(NULL != sock_ev_write_struct->buffer)
        {
            free(sock_ev_write_struct->buffer);  //删除buffer
        }
        free(sock_ev_write_struct);   //释放整个结构体
    }
}

/* ***********************************
 * 函数名：destroy_sock_ev()
 * 功能：读事件结束后，用于销毁相应的资源
 * 参数：sock_ev_struct
 * 返回值：
 * ***********************************/
void destroy_sock_ev(struct sock_ev* sock_ev_struct)
{
    if(NULL == sock_ev_struct)
        return;
    event_del(sock_ev_struct->read_ev);
    event_base_loopexit(sock_ev_struct->base, NULL);    //停止loop循环
    if(NULL != sock_ev_struct->read_ev)
    {
        free(sock_ev_struct->read_ev);
    }
    event_base_free(sock_ev_struct->base);    //释放base
    free(sock_ev_struct);  //释放整个结构体
}
